using Microsoft.EntityFrameworkCore;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.BlobStoring.Database.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.FeatureManagement.EntityFrameworkCore;
using Volo.Abp.Identity;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.OpenIddict.EntityFrameworkCore;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using Mes.Pendant.WorkstationFiles;
using Mes.Pendant.MaterialTypes;
using Mes.Pendant.MaterialManagements;
using Mes.Pendant.UnitMeasureW;
using Mes.Pendant.CustomerManagementTable;
using Mes.Pendant.SupplierManagements;
using Mes.Pendant.WorkshopSetups;
using Mes.Pendant.NotificationArrivals;
using Mes.Pendant.Warehousings;
using Mes.Pendant.ProductionWorkOrders;
using Mes.Pendant.ProcurementWarehousings;
using Mes.Pendant.WarehousesettingW;
using Mes.Pendant.RBACFiles;
using Mes.Pendant.Productionrequisitions;


namespace Mes.Pendant.EntityFrameworkCore;

[ReplaceDbContext(typeof(IIdentityDbContext))]
[ReplaceDbContext(typeof(ITenantManagementDbContext))]
[ConnectionStringName("Default")]
public class PendantDbContext :
	AbpDbContext<PendantDbContext>,
	ITenantManagementDbContext,
	IIdentityDbContext
{
	/* Add DbSet properties for your Aggregate Roots / Entities here. */


	#region Entities from the modules

	/* Notice: We only implemented IIdentityProDbContext and ISaasDbContext
     * and replaced them for this DbContext. This allows you to perform JOIN
     * queries for the entities of these modules over the repositories easily. You
     * typically don't need that for other modules. But, if you need, you can
     * implement the DbContext interface of the needed module and use ReplaceDbContext
     * attribute just like IIdentityProDbContext and ISaasDbContext.
     *
     * More info: Replacing a DbContext of a module ensures that the related module
     * uses this DbContext on runtime. Otherwise, it will use its own DbContext class.
     */
	public DbSet<Workstation> Workstation { get; set; }
	// Identity
	public DbSet<IdentityUser> Users { get; set; }
	public DbSet<IdentityRole> Roles { get; set; }
	public DbSet<IdentityClaimType> ClaimTypes { get; set; }
	public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
	public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
	public DbSet<IdentityLinkUser> LinkUsers { get; set; }
	public DbSet<IdentityUserDelegation> UserDelegations { get; set; }
	public DbSet<IdentitySession> Sessions { get; set; }

	// Tenant Management
	public DbSet<Tenant> Tenants { get; set; }
	public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; }
	public DbSet<MaterialType> MaterialType { get; set; }
	public DbSet<MaterialManagement> MaterialManagement { get; set; }
    public DbSet<CustomerManagement> CustomerManagement { get; set; }
    public DbSet<UnitMeasure> UnitMeasure { get; set; }
    public DbSet<SupplierManagement> suppliermanagement { get; set; }
    public DbSet<ProcurementWarehousing> procurementwarehousing { get; set; }

    public DbSet<Warehousing> warehousing { get; set; }
    #endregion
	public DbSet<CustomerManagement> CustomerManagement { get; set; }
	public DbSet<UnitMeasure> UnitMeasure { get; set; }
	public DbSet<SupplierManagement> suppliermanagement { get; set; }
	public DbSet<ProcurementWarehousing> procurementwarehousing { get; set; }
	#endregion

    public DbSet<Permission> Permission { get; set; }
	public DbSet<Role> Role { get; set; }
	public DbSet<RolePermission> RolePermission { get; set; }
	public DbSet<User> User { get; set; }
	public DbSet<UserRole> UserRole { get; set; }




	public DbSet<WorkshopSetup> WorkshopSetup { get; set; }
	public DbSet<Warehousesettings> Warehousesettings { get; set; }
	public DbSet<Productionrequisition> Productionrequisition { get; set; }

	public DbSet<NotificationArrival> NotificationArrival { get; set; }

	public DbSet<Warehousing> Warehousing { get; set; }
	//public DbSet<SupplierManagement> suppliermanagement { get; set; }
	public DbSet<ProductionWorkOrder> ProductionWorkOrder { get; set; }
	public DbSet<SupplierReturnFiles.SupplierReturn> SupplierReturn { get; set; }


	public PendantDbContext(DbContextOptions<PendantDbContext> options)
		: base(options)
	{

	}

	protected override void OnModelCreating(ModelBuilder builder)
	{
		base.OnModelCreating(builder);

		/* Include modules to your migration db context */

		builder.ConfigurePermissionManagement();
		builder.ConfigureSettingManagement();
		builder.ConfigureBackgroundJobs();
		builder.ConfigureAuditLogging();
		builder.ConfigureFeatureManagement();
		builder.ConfigureIdentity();
		builder.ConfigureOpenIddict();
		builder.ConfigureTenantManagement();
		builder.ConfigureBlobStoring();

		/* Configure your own tables/entities inside here */

		//builder.Entity<YourEntity>(b =>
		//{
		//    b.ToTable(PendantConsts.DbTablePrefix + "YourEntities", PendantConsts.DbSchema);
		//    b.ConfigureByConvention(); //auto configure for the base class props
		//    //...
		//});
	}
}
